//
//  Constants.swift
//  StoryDemo
//
//  Created by mac on 2019/7/5.
//  Copyright © 2019年 zhkj. All rights reserved.
//
import UIKit
import Foundation

let kIsIPhoneX = UIScreen.main.bounds.size.equalTo(CGSize (width: 375, height: 812))
let kNavigationBarHeight:CGFloat = kIsIPhoneX ? 88 : 64
let kBottomToolBarHeight:CGFloat = kIsIPhoneX ? 80 : 49

let kStatusBarHeight:CGFloat = UIApplication.shared.statusBarFrame.height

let screenW=UIScreen.main.bounds.width
let screenH=UIScreen.main.bounds.height
func kSize(width:CGFloat)->CGFloat{
    return CGFloat(width*(screenW/375))
}
func cutCorner(cornerRadius:CGFloat,borderWidth:CGFloat,borderColor:UIColor,view:UIView)
{
    view.layer.cornerRadius = cornerRadius
    view.layer.borderColor = borderColor.cgColor
    view.layer.borderWidth = borderWidth
    view.layer.masksToBounds = true
}

let app_key="himalltest"
let secret="has2f5zbd4"
var userkey=UserDefaults.standard.string(forKey: "UserKey")
var UserID=UserDefaults.standard.string(forKey: "UserID")
var adminToken=UserDefaults.standard.string(forKey: "adminToken")

let BASE_URL = "http://mall.xigyu.com/"//商城正式服
//let BASE_URL = "http://47.111.124.153/"//商城测试服
//let BASE_URL = "http://42.51.69.35:8812/"//商城测试服
let BASE_URL2 = "http://47.96.126.145:8001/api/"//工厂师傅正式服
//let BASE_URL2 = "http://47.111.124.153:8001/api/"//工厂师傅测试服
//let BASE_URL2 = "http://42.51.69.35:8810/api/"//工厂师傅测试服

//===================================工厂师傅接口===============================================
let ValidateUserName=BASE_URL2+"Account/ValidateUserName"
let GettokenbyUserid=BASE_URL2+"account/GettokenbyUserid"//获取token
let LoginOn=BASE_URL2+"Account/LoginOn"//登录
let GetUserInfoList=BASE_URL2+"Account/GetUserInfoList"//西瓜鱼用户信息
let LoginOnMessage=BASE_URL2+"Account/LoginOnMessage"//验证码登录
let AddAndUpdatePushAccount=BASE_URL2+"Message/AddAndUpdatePushAccount"//推送
let GetFactoryCategory=BASE_URL2+"FactoryConfig/GetFactoryCategory"//获取分类
let GetBrandByCategory=BASE_URL2+"FactoryConfig/GetBrandByCategory"//获取品牌
let AddOrder=BASE_URL2+"Order/AddOrder"//发单
let FactoryGetOrderList=BASE_URL2+"Order/FactoryGetOrderList"//获取服务工单列表
let UpdateOrderState=BASE_URL2+"Order/UpdateOrderState"//更新工单状态
let ApplyCancelOrder=BASE_URL2+"order/ApplyCancelOrder"//工单作废
let FactoryComplaint=BASE_URL2+"Order/FactoryComplaint"//工厂投诉
let FactoryEnsureOrder=BASE_URL2+"Order/FactoryEnsureOrder"//工厂确认工单 结算
let EnSureOrder=BASE_URL2+"Order/EnSureOrder"//用户确认订单 结算
let ApplyCustomService=BASE_URL2+"Order/ApplyCustomService"//发起质保
let ApproveBeyondMoney=BASE_URL2+"Order/ApproveBeyondMoney"//审核远程费
let ApproveOrderAccessory=BASE_URL2+"Order/ApproveOrderAccessory"//审核配件申请
let AddOrUpdateExpressNo=BASE_URL2+"Order/AddOrUpdateExpressNo"//工厂添加配件快递信息
let UpdateIsReturnByOrderID=BASE_URL2+"Order/UpdateIsReturnByOrderID"//旧件是否需要返件
let GetOrderRecordByOrderID=BASE_URL2+"Order/GetOrderRecordByOrderID"//工单跟踪
let GetExpressInfo=BASE_URL2+"Order/GetExpressInfo"//物流信息
let GetOrderInfo=BASE_URL2+"Order/GetOrderInfo"//工单详情
let GetOrderStr=BASE_URL2+"Pay/GetOrderStr"//支付宝
let GetWXOrderStr=BASE_URL2+"Pay/GetWXOrderStr"//微信
let MallBalancePay=BASE_URL2+"Mall/MallBalancePay"//余额
let WXNotifyManual=BASE_URL2+"Pay/WXNotifyManual"//微信人工回调OutTradeNo
let FAddCon=BASE_URL2+"Account/FAddCon"//赠送西瓜币
let GetOrderByhmall=BASE_URL2+"Order/GetOrderByhmall"//获取待支付工单
let GetOrderByhmalluserid=BASE_URL2+"Order/GetOrderByhmalluserid"//获取待支付工单
let AddorUpdateAccountPayInfo=BASE_URL2+"Account/AddorUpdateAccountPayInfo"//添加银行卡
let GetAccountPayInfoList=BASE_URL2+"Account/GetAccountPayInfoList"//获取银行卡
let GetBankNameByCardNo=BASE_URL2+"Account/GetBankNameByCardNo"//根据银行卡号获取银行名 判断后台是否支持该银行的提现
let IsMallid=BASE_URL2+"Order/IsMallid"//判断商品订单号是否发起过保内安装
let ChangePayPassword=BASE_URL2+"Account/ChangePayPassword"//修改支付密码
let PressWokerAccount=BASE_URL2+"Order/PressWokerAccount"//催单
let UpdateAccountNickName=BASE_URL2+"Account/UpdateAccountNickName"//修改昵称
let UpdateSex=BASE_URL2+"Account/UpdateSex"//修改性别
let AddOpinion=BASE_URL2+"Account/AddOpinion"//意见反馈
let CoinList=BASE_URL2+"mall/CoinList"//西瓜币明细
//===================================商城接口===============================================
let Get = BASE_URL+"api/home/Get"//首页
let home_json=BASE_URL+"AppHome/data/default.json"//首页
let GetlismitBuyList=BASE_URL+"api/LimitTimeBuy/GetLismitBuyList"//抢购列表
let GetCategories=BASE_URL+"api/Category/GetCategories"//所有分类
let GetProductDetail=BASE_URL+"api/product/GetProductDetail"//商品详情
let GetSKUInfo=BASE_URL+"api/product/GetSKUInfo"//商品sku
let integral_mall=BASE_URL+"IntegralMall/IndexJson"//西瓜币商城
let GetCartProduct=BASE_URL+"api/Cart/GetCartProduct"//购物车
let PostAddProductToCart=BASE_URL+"api/Cart/PostAddProductToCart"//添加商品到购物车
let PostUpdateCartItem=BASE_URL+"api/Cart/PostUpdateCartItem"//提交订单时同步数量到后台
let GetUser=BASE_URL+"api/Login/GetUser"//登录
let PostRegisterUser=BASE_URL+"api/Register/PostRegisterUser"//注册
let GetPhoneOrEmailCheckCode=BASE_URL+"api/Register/GetPhoneOrEmailCheckCode"//注册验证码
let GetCheckPhoneOrEmailCheckCode=BASE_URL+"aapi/Register/GetCheckPhoneOrEmailCheckCode"//验证注册验证码是否正确
let UserCenter_GetUser=BASE_URL+"api/UserCenter/GetUser"//获取个人信息

let GetPhoneCode=BASE_URL+"api/login/GetPhoneCode"//验证码
let GetUserWithoutPassword=BASE_URL+"api/Login/GetUserWithoutPassword"//验证码登录

//地址相关
let GetShippingAddressList=BASE_URL+"api/ShippingAddress/GetShippingAddressList"//收货地址列表
let PostAddShippingAddress=BASE_URL+"api/ShippingAddress/PostAddShippingAddress"//新增收货地址
let PostEditShippingAddress=BASE_URL+"api/ShippingAddress/PostEditShippingAddress"//编辑收货地址
let PostDeleteShippingAddress=BASE_URL+"api/ShippingAddress/PostDeleteShippingAddress"//删除收货地址
let GetAllRegion=BASE_URL+"common/RegionAPI/GetAllRegion"//获取省市区
let GetSubRegion=BASE_URL+"common/RegionAPI/GetSubRegion"//获取街道
let GetRegion=BASE_URL+"common/RegionAPI/GetRegion"//获取省市区code
//订单相关

let PostSubmitOrderByCart=BASE_URL+"api/Order/PostSubmitOrderByCart"//购物车提交
let PostSubmitOrder=BASE_URL+"api/Order/PostSubmitOrder"//立即购买提交
let GetSubmitModel=BASE_URL+"api/Order/GetSubmitModel"//取提交MODEL
let GetSubmitByCartModel=BASE_URL+"api/Order/GetSubmitByCartModel"//取购物车提交的MODEL
let GetOrders=BASE_URL+"api/MemberOrder/GetOrders"//订单列表
let PostChangeOrderState=BASE_URL+"api/MemberOrder/PostChangeOrderState"//更新订单状态
let GetOrderDetail=BASE_URL+"api/MemberOrder/GetOrderDetail"//获取订单详情
let PostCloseOrder=BASE_URL+"api/MemberOrder/PostCloseOrder"//取消订单
let CancelOrder=BASE_URL+"api/Order/CancelOrder"//删除订单
let PostConfirmOrder=BASE_URL+"api/MemberOrder/PostConfirmOrder"//确认收货
//搜索
let GetSearchProducts=BASE_URL+"api/search/GetSearchProducts"//搜索
let GetSearchFilter=BASE_URL+"api/search/GetSearchFilter"//筛选
//积分商城
let GetGifts=BASE_URL+"api/Gifts/GetGifts"//积分详情
let ConfirmOrder=BASE_URL+"api/Gifts/ConfirmOrder"//积分确认订单
let SubmitOrder=BASE_URL+"api/Gifts/SubmitOrder"//积分提交订单
let GetMyOrderList=BASE_URL+"api/Gifts/GetMyOrderList"//积分订单列表
let ConfirmOrderOver=BASE_URL+"api/Gifts/ConfirmOrderOver"//积分订单确认收货
let GetOrderCount=BASE_URL+"api/Gifts/GetOrderCount"//积分订单各状态数量
let GetOrder=BASE_URL+"api/Gifts/GetOrder"//积分订单详情
//足迹
let GetHistoryVisite=BASE_URL+"api/product/GetHistoryVisite"//足迹

let GetUserCollectionProduct=BASE_URL+"api/UserCenter/GetUserCollectionProduct"//用户收藏的商品
let GetUserCollectionShop=BASE_URL+"api/UserCenter/GetUserCollectionShop"//用户收藏的店铺

let GetUserCounponList=BASE_URL+"api/coupon/GetUserCounponList"//我的优惠券列表
let GetHotProduct=BASE_URL+"product/GetHotProduct"//猜你喜欢，找相似

///
let Loading = {HUD.show()}
let Loadingwith:((String)->()) = {str in
    HUD.show(withStatus:str)
}
let Dismiss = {HUD.dismiss()}



public func SignTopRequest(params:Dictionary<String,String>) -> String {
    var str = ""
    let sortedKeys = Array(params.keys).sorted()
    for key in sortedKeys {
        if params[key] != ""{
            str+=key.lowercased()+params[key]!
        }
    }
    return md5(strs: str+secret).uppercased()
}
public func md5(strs:String) ->String!{
    let str = strs.cString(using: String.Encoding.utf8)
    let strLen = CUnsignedInt(strs.lengthOfBytes(using: String.Encoding.utf8))
    let digestLen = Int(CC_MD5_DIGEST_LENGTH)
    let result = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: digestLen)
    CC_MD5(str!, strLen, result)
    let hash = NSMutableString()
    for i in 0 ..< digestLen {
        hash.appendFormat("%02x", result[i])
    }
    //    result.deinitialize(count: result.hashValue)
    return String(format: hash as String)
}
//获取当前时间戳
public func getTimestamp() ->String!{
    let dateformatter = DateFormatter()
    dateformatter.dateFormat = "yyyy-MM-dd HH:mm:ss"// 自定义时间格式
    let timestamp = dateformatter.string(from: Date())
    return timestamp
}
//日期转时间戳
public func getTimestampFromDate(date:Date) ->String!{
    let dateformatter = DateFormatter()
    dateformatter.dateFormat = "yyyy-MM-dd HH:mm:ss"// 自定义时间格式
    let timestamp = dateformatter.string(from: date)
    return timestamp
}
//时间字符串转date
public func getDateFromTime(time:String) ->Date{
    let dateformatter = DateFormatter()
    //自定义日期格式
    dateformatter.dateFormat="yyyy-MM-dd HH:mm:ss"
    return dateformatter.date(from: time)!
}

